﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using SangsTools;
using DG.Tweening;

namespace UI
{
    public class UIDesItem : MonoBehaviour
    {
        private Text text;
        private string strFollowerID;
        public string CurText => text?.text;

        private void Awake()
        {
            text = GetComponentInChildren<Text>();
        }

        public UIDesItem Show(string des, Transform target)
        {
            transform.DOKill();
            transform.DOScale(Vector3.one, 0.3f);

            text.text = des;
            strFollowerID = PosFollowerMgr.AddNormalFollower(transform, target);
            return this;
        }

        public void SetText(string text)
        {
            this.text.text = text;
        }

        public void Hide()
        {
            transform.DOKill();
            transform.DOScale(Vector3.zero, 0.3f).OnComplete(() => UIDesCanvas.Ins.RecycleDesItem(this));
        }

        public void RemoveFollower()
        {
            if (!string.IsNullOrEmpty(strFollowerID))
                PosFollowerMgr.RemoveFollowerData(strFollowerID);
            strFollowerID = null;
        }
    }
}